<template>
  <div class="InforBase-container">
    <!-- 面包屑导航 -->
    <el-card class="filter-card">
      <div slot="header" class="clearfix">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>量化考核表</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <!-- 数据筛选表单 -->
      <el-form ref="form" :model="queryForm" label-width="70px" size="small">
        <el-form-item label="状态">
          <el-radio-group v-model="queryForm.politic">
            <el-radio label="">全部</el-radio>
            <el-radio label="共青团员">待审核</el-radio>
            <el-radio label="积极分子">未审核</el-radio>
            <el-radio label="发展对象">未更新</el-radio>
            <el-radio label="共产党员">完成考核</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="选择年级">
          <el-select v-model="queryForm.major" placeholder="请选择年级">
            <el-option label="全部" :value="null"></el-option>
            <el-option
              :label="major"
              :value="major"
              v-for="(major, index) in majors"
              :key="index"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学号查询">
          <el-input v-model="queryForm.studentNumber"></el-input>
          <el-button
            type="primary"
            :disabled="loading"
            @click="list(1)"
            style="margin-left: 10px"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="font-size: 17px">根据筛选条件查询到的结果</span>
      </div>
      <el-table
        v-loading="loading"
        class="list-lable"
        :data="infor"
        style="width: 100%"
        stripe
      >
        <el-table-column fixed prop="username" label="姓名" width="80">
        </el-table-column>
        <el-table-column prop="studentNumber" label="学号"> </el-table-column>
        <el-table-column prop="sex" label="学院"> </el-table-column>
        <el-table-column prop="nation" label="年级"> </el-table-column>
        <el-table-column prop="register" label="专业班级"> </el-table-column>
        <el-table-column prop="major" label="确定积极分子时间">
        </el-table-column>
        <el-table-column prop="politic" label="累计分数"> </el-table-column>
        <el-table-column prop="tel" label="排名" width="120"> </el-table-column>
        <el-table-column label="状态">
          <template #default="{ row }">
            <el-tag v-if="row.politic === '共青团员'" type="success"
              >共青团员</el-tag
            >
            <el-tag v-else-if="row.politic === '积极分子'" type="info"
              >积极分子</el-tag
            >
            <el-tag v-else-if="row.politic === '发展对象'" type="warning"
              >发展对象</el-tag
            >
            <el-tag v-else-if="row.politic === '共产党员'" type="danger"
              >共产党员</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="查看详情" width="120">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              circle
              icon="el-icon-edit"
              @click="toDetails(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-pagination
        background
        @size-change="list"
        @current-change="list"
        :current-page.sync="queryForm.pageNum"
        :page-sizes="[10, 25, 50, 100]"
        :page-size.sync="queryForm.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import {
  list, // 获取学生列表
  deleteArticle
} from '@/api/InforBase'

import {
  getMajors // 获取专业列表
} from '@/api/AppliForm'
export default {
  name: 'InfonbaseIndex',
  components: {},
  props: {},
  data () {
    return {
      queryForm: {
        pageNum: 1,
        pageSize: 10,
        politic: null, // 政治身份
        studentNumber: null, // 学号
        major: null // 查询的专业
      },
      infor: [], // 信息列表
      total: 0, // 总数据条数
      majors: [], // 专业列表
      loading: true // 表格数据加载中
    }
  },
  computed: {},
  watch: {},
  created () {
    this.init()
  },
  mounted () { },
  methods: {
    init () {
      // 获取学生列表
      this.list()
      // 获取专业列表
      this.getMajors()
    },
    async list () {
      try {
        this.loading = true
        const res = await list(this.queryForm)
        this.infor = res.data.records
        this.total = res.data.total
      } finally {
        this.loading = false
      }
    },
    getMajors () {
      getMajors().then(res => {
        this.majors = res.data
      })
    },
    toDetails (row) {
      // this.$router.push({ name: 'Study', query: { studentNumber: row.studentNumber } })
      this.$router.push({ path: '/developInspection/detail', query: { studentNumber: row.studentNumber } })
    }
  }
}
</script>

<style>
.filter-card {
  margin-bottom: 20px;
}
.list-lable {
  margin-bottom: 20px;
}
</style>
